package cn.yr.oauth.configuration;

import cn.yr.oauth.properties.WeiboProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthWeiboRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(WeiboProperties.class)
@ConditionalOnProperty(
        prefix = "oauth.weibo",
        name = "appKey"
)
public class WeiboConfiguration {

    @Autowired
    private WeiboProperties weiboProperties;

    @Bean
    public AuthWeiboRequest getAuthWeiboRequest(){
        return new AuthWeiboRequest(AuthConfig.builder()
                .clientId(weiboProperties.getAppKey())
                .clientSecret(weiboProperties.getAppSecret())
                .redirectUri(weiboProperties.getRedirectUrl())
                .build());
    }

}
